function success(data = null, message = 'success', code = 200) {
  return {
    success: true,
    code,
    message,
    data
  }
}

function error(message = 'error', code = 500, data = null) {
  return {
    success: false,
    code,
    message,
    data
  }
}

function handleResponse(res, result) {
  if (result.success) {
    res.status(result.code).json(result)
  } else {
    res.status(result.code).json(result)
  }
}

module.exports = {
  success,
  error,
  handleResponse
}
